package com.linln.modules.userule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linln.common.vo.PageResult;
import com.linln.modules.userule.repository.UseRuleMapper;
import com.linln.modules.userule.domain.UseRule;
import com.linln.modules.userule.service.UseRuleService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.modules.userule.service.impl
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.modules.userule.service.impl
 * @Description: TODO
 * @date Date : 2020年12月29日 11:44
 */

@Service
public class UseRuleServiceImpl extends ServiceImpl<UseRuleMapper, UseRule> implements UseRuleService {


    @Override
    public PageResult<UseRule> getUseRuleList(Integer pageNum, Integer limit, String useRuleName) {
        PageHelper.startPage(pageNum, limit);
        QueryWrapper<UseRule> queryWrapper = null;
        if (!Strings.isBlank(useRuleName)) {
            queryWrapper = new QueryWrapper<UseRule>().like("use_rule_name", useRuleName);
        }
        PageInfo<UseRule> pageInfo = new PageInfo<>(this.list(queryWrapper));
        PageResult<UseRule> pageResult = new PageResult<>();
        pageResult.setData(pageInfo.getList());
        pageResult.setCount(pageInfo.getTotal());
        return pageResult;
    }

    @Override
    public boolean addUseRule(UseRule useRule) {
        return this.save(useRule);
    }

    @Override
    public boolean updateUseRule(UseRule useRule) {
        return this.updateById(useRule);
    }

    @Override
    public boolean delUseRule(String useRuleId) {
        return this.removeById(useRuleId);
    }
}
